package backend.model.charisma;

import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@NamedQueries({
        @NamedQuery(name = "loadCharismaWorkLogForDateAndEmployeeIdentificationCard",
                query = "from CharismaWorkLog where compoundKey.identificationCard = :identificationCard and compoundKey.date = :date"),
        @NamedQuery(name = "loadCharismaWorkLogForTimeIntervalAndEmployeeIdentificationCard",
                query = "from CharismaWorkLog where compoundKey.identificationCard = :identificationCard and compoundKey.date >= :startDate and compoundKey.date <= :endDate"),
})

@Entity
@Table(name = "Pontaj")
public class CharismaWorkLog extends DBModel {

    @Id
    private CharismaWorkLogCompoundKey compoundKey;

    @Column(name = "Prenume")
    private String lastName;

    @Column(name = "Nume")
    private String firstName;

    @Column(name = "Ore")
    private int hours;

    public CharismaWorkLogCompoundKey getCompoundKey() {
        return compoundKey;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    @Override
    public int getId() {
        return 0;
    }

    @Override
    public boolean getIsActive() {
        return true;
    }

    @Override
    public String getDisplayLabel() {
        return "Charisma booked hours: " + getCompoundKey().getDate() + " ("+ getHours() + ")";
    }

    @Override
    public int compareTo(Object o) {
        if (!(o instanceof CharismaWorkLog)) {
            return -1;
        } else {
            CharismaWorkLog otherWorkLog = (CharismaWorkLog) o;
            return getDisplayLabel().compareTo(otherWorkLog.getDisplayLabel());
        }
    }
}
